#include "outline/fast_bspline_adjust.h"
#include "outline/segmap_impl.h"
#include "outline/bspline_opt.h"

namespace outline {

template <typename T, typename R>
R fast_bspline_adjust(
	std::vector< point<T> > const & nodes,
	fast_bspline_adjust_params const & params,
	controls<R> & ctrls,
	std::vector<junc_type> const & junc,
	std::vector< point<R> > * poles,
	std::vector< point<R> > * samples,
	std::vector< point<R> > const * attractors,
	std::vector<R> const * tractions,
	std::vector<int> const * fixed_dir_tangents
)
{
	segmap<T> target(nodes.begin(), nodes.end());
	target.search_half_window(params.search_half_window);

	bspline_opt<T,R>::doit(
		target, junc,
		params,
		ctrls, 
		attractors, tractions, fixed_dir_tangents,
		poles, samples);
	return 0;
}

#define INSTANTIATE(T,R) \
template R fast_bspline_adjust( \
	std::vector< point<T> > const & nodes, \
	fast_bspline_adjust_params const & params, \
	controls<R> & ctrls, \
	std::vector<junc_type> const & junc, \
	std::vector< point<R> > * poles, \
	std::vector< point<R> > * samples, \
	std::vector< point<R> > const * attractors, \
	std::vector<R> const * tractions, \
	std::vector<int> const * fixed_dir_tangents \
);

INSTANTIATE(unsigned short, float)
INSTANTIATE(unsigned short, double)
INSTANTIATE(short, float)
INSTANTIATE(int, float)
INSTANTIATE(float, float)
INSTANTIATE(double, double)

} //namespace outline
